import Vue from 'vue'
import VueRouter from 'vue-router';
/* Layout */
import Layout from '@/layout'

// 解决Redirected when going from "/login" to "/system/user" via a navigation guard.的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

// 公共路由
export const constantRoutes = [{
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [{
            path: '/redirect/:path(.*)',
            component: (resolve) => require(['@/views/redirect'], resolve)
        }]
    },
    {
        path: '/login',
        hidden: true,
        component: (resolve) => require(['@/views/login'], resolve)
    },
    {
        path: '/',
        hidden: true,
        component: Layout,
        redirect: '/index/index',
        children: [{
            name: "Index",
            path: '/index/index',
            component: (resolve) => require(['@/views/index'], resolve),
            meta: { title: '首页', icon: 'reading', noCache: true, affix: true }
        }]
    },
    // {
    //     path: '/',
    //     component: Layout,
    //     redirect: 'index',
    //     meta: { titleShort: '首页', icon: 'reading', noCache: true, affix: true },
    //     children: [
    //       {
    //         path: 'index',
    //         component: (resolve) => require(['@/views/index'], resolve),
    //         name: '首页',
    //         meta: { title: '首页', icon: 'reading', noCache: true, affix: true }
    //       }
    //     ]
    //   },
    {
        path:'/detailList',
        hidden: true,
        component: (resolve) => require(['@/views/data/detail/detailList'], resolve)
    },
    {
        path: '/404',
        component: (resolve) => require(['@/views/error/404'], resolve),
        hidden: true
      },
      {
        path: '/401',
        component: (resolve) => require(['@/views/error/401'], resolve),
        hidden: true
      },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: constantRoutes
})

export default router